<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
	    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="easyui/themes/color.css">
        <script type="text/javascript" src="easyui/jquery.min.js"></script>
        <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
        <link rel="stylesheet" href="layui/css/layui.css" media="all">
        <script type="text/javascript" src="layui/layui.all.js"></script>
        <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="easyui/plugins/datagrid-filter.js"></script>
    </head>
    <body>
         <table id="dat" class="easyui-datagrid" title="" data-options="fit:true,singleSelect:false,
                                                                   selectOnCheck:true,ctrlSelect:true,
                                                                   fitColumns:true,rownumbers:true,remoteFilter: true,
                                                                   pagination:true,clientPaging: false,
                                                                   collapsible:false,idField:'id',
                                                                   toolbar:toolbars,pageSize:20">
	        <thead>
	            <tr>
	                     <th data-options="field:'uname',width:200">用户昵称</th>
	                     <th data-options="field:'currency_title',width:200">币种</th>
	                     <th data-options="field:'amount',width:200,formatter:showBcRecordTitle">可用金额</th>
	                     <th data-options="field:'frozen_amount',width:200">冻结金额</th>
	                     <th data-options="field:'invest_amount',width:200,formatter:showInvestTitle">投资金额</th>
	                     <th data-options="field:'static_bonus',width:200">静态收益</th>
	                     <th data-options="field:'team_bonus',width:200">团队收益</th>
	                     <th data-options="field:'total_bonus',width:200">总收益</th>
	            </tr>
	        </thead>
	        
	    </table>
	    <div id="form" style="width:100%;padding:30px 60px;"></div>
	    
    </body>
    <script type="text/javascript">
		    var toolbars = [/* {
		        text:'新增',
		        iconCls:'icon-add',
		        handler:function(){
		        	$('#form').dialog({
		        	    title: '新增表单',
		        	    width: 500,
		        	    height: 380,
		        	    closed: false,
		        	    cache: false,
		        	    href: 'to?page=app/account/form',
		        	    modal: true,
		        	    onClose:function(){
		        	    	$('#dat').datagrid('reload');
		        	    },
		        	    onDestroy:function(){
		        	    	$('#dat').datagrid('reload');
		        	    }
		        	});
		        }
		    },*/{
		        text:'修改',
		        iconCls:'icon-edit',
		        handler:function(){
		        	var data=$('#dat').datagrid('getSelected');
		        	if(data&&data.id){
		        		$('#form').dialog({
			        	    title: '修改表单',
			        	    width: 500,
			        	    height: 380,
			        	    closed: false,
			        	    cache: false,
			        	    href: 'app/account/form?id='+data.id,
			        	    modal: true,
			        	    onClose:function(){
			        	    	$('#dat').datagrid('reload');
			        	    },
			        	    onDestroy:function(){
			        	    	$('#dat').datagrid('reload');
			        	    }
			        	});
		        	}else{
		        		layer.alert('请选择记录');
		        	}
		        }
		    },'-',/*{
		        text:'删除',
		        iconCls:'icon-remove',
		        handler:function(){
		        	var data=$('#dat').datagrid('getSelections');
		        	if(data&&data.length>0){
		        		layer.confirm('确定要删除码?',function(index){
		        			var key='';
		        			var ids='';
		        			if(data instanceof Array){
		        				$.each(data,function(index,value){
	                            	if(index>0){
	                            		ids+=',';
	                            	}
	                            	ids+=value.id;
	                            })
		        			}else{
		        				key=data.id;
		        			}
		        			
                            
                            
                            $.post('app/account/delete',{'id':key,'ids':ids},function(r){
                            	if(r.code>0){
                            		layer.alert('删除失败',function(){
                            			layer.close(index);			
                            		});
                            	}else{
                            		layer.close(index);
                            		$('#dat').datagrid('reload');
                            	}
                            },"json")
		        			
		        		});
		        	}
		        }
		    }, */{
		    	text:'刷新',
		    	iconCls:'icon-reload',
		        handler:function(){
		        	$('#dat').datagrid('reload');
		        }
		    }];
		    
		    
		    $('#dat').datagrid({
		    	loader:function(params,success,error){
		    		var pm={'pageNow':1,'pageSize':20};
		    		if(params&&params.page){
		    			pm.pageNow=params.page;
		    		}
		    		if(params&&params.rows){
		    			pm.pageSize=params.rows;
		    		}
		    		if(params&&params.filterRules){
		    			$.each(JSON.parse(params.filterRules),function(index,item){
		    				pm[item.field]=item.value;
		    			})
		    		}
		    		$.post('app/account/page',pm,function(r){
		    			success(r.result);
		    		},"json")
		    	},
		    	loadFilter: function(r){
		    		if (r){
		    			return {'rows':r.data,'total':r.total};
		    		}
		    	},
		    	onLoadSuccess:function(){
		    		$('#dat').datagrid('enableFilter');
		    	}
		    });
		    
		    
		    function showBcRecord(customer_id){
		    	layer.open({
		    		type:2,
		    		title:'充币记录',
		    		area: ['850px', '600px'],
		    		content:'to?page=app/bcRecord/list&customer_id='+customer_id
		    	})
		    	console.log(customer_id)
		    }
		    
		    function showInvestRecord(customer_id){
		    	layer.open({
		    		type:2,
		    		title:'投资记录',
		    		area: ['850px', '600px'],
		    		content:'to?page=app/invest/list&customer_id='+customer_id
		    	})
		    	console.log(customer_id)
		    }
		    
		    function showBcRecordTitle(value,row,index){
		    	return '<a href="javascript:void(0)" title="查看详细记录" style="color:blue" onclick="showBcRecord('+row.customer_id+')">'+value+'</a>';
		    }
		    
		    function showInvestTitle(value,row,index){
		    	return '<a href="javascript:void(0)" title="查看详细记录" style="color:blue" onclick="showInvestRecord('+row.customer_id+')">'+value+'</a>';
		    }
		  		   
		 		    
    </script>
</html>